package com.oasys.controller;

import com.github.pagehelper.PageInfo;
import com.oasys.entity.po.RolePo;
import com.oasys.entity.vo.RoleVo;
import com.oasys.enums.OaResponseCode;
import com.oasys.service.JobService;
import com.oasys.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2022/5/11
 * 职位控制器
 **/
@RestController
@RequestMapping("/job")
@Api("职位-角色信息")
@Slf4j
public class JobController {

    @Resource
    private JobService jobService;

    /**
     * 查询职位信息
     * @param page page
     * @param size size
     * @param jobName name
     * @return map
     */
    @GetMapping("/queryJobByPage/{page}/{size}")
    public ResponseResult<Map<String,Object>> queryJobByPage(@PathVariable("page")Integer page,@PathVariable("size")Integer size,String jobName){
        Map<String,Object> map = new HashMap<>(8);
        PageInfo<RolePo> job = jobService.queryJobByPage(jobName, page, size);
        map.put("jobList",job.getList());
        map.put("totals",job.getTotal());
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),OaResponseCode.SUCCESS.getMsg(),map);
    }

    /**
     * add
     * @param jobName name
     * @return true
     */
    @PostMapping("/addJob")
    public ResponseResult<Boolean> addJob(@RequestParam String jobName){
        Boolean bool = jobService.addJob(jobName);
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),OaResponseCode.SUCCESS.getMsg(),bool);
    }

    /**
     * 修改职位
     * @param roleVo
     * @return
     */
    @PostMapping("/updateJob")
    @ApiOperation("修改职位信息")
    public ResponseResult<Boolean> updateJob(@RequestBody RoleVo roleVo){
        log.info("职位信息:{}",roleVo.toString());
        Boolean result = jobService.updateJob(roleVo);
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),OaResponseCode.SUCCESS.getMsg(),result);
    }

    /**
     * 删除职位
     * @param jobId
     * @return
     */
    @GetMapping("/delJob/{roleId}")
    @ApiOperation("删除职位信息")
    public ResponseResult<Boolean> delJob(@PathVariable("roleId") Long jobId){
        log.info("删除职位id:{}",jobId);
        Boolean result = jobService.delJob(jobId);
        return new ResponseResult<>(OaResponseCode.SUCCESS.getCode(),OaResponseCode.SUCCESS.getMsg(),result);
    }
}
